package com.loby.data.pojo;

import com.loby.data.base.pojo.TMonMonitorStation;
import com.loby.data.base.pojo.TMonPollutionSources;
import com.loby.data.code.pojo.TCodeAdministrativeDivision;
import com.loby.data.view.pojo.VStationTree;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@Data
public class DivisionTree implements Serializable {
    Map<TCodeAdministrativeDivision, Map<TCodeAdministrativeDivision, Map<TCodeAdministrativeDivision, PollutionSourceTreeItem>>> tree;

    public void put(TCodeAdministrativeDivision div1, TCodeAdministrativeDivision div2, TCodeAdministrativeDivision div3, VStationTree item, TMonMonitorStation station) {
        if(tree == null) {
            tree = new HashMap<>(1);
        }
        Map<TCodeAdministrativeDivision, Map<TCodeAdministrativeDivision, PollutionSourceTreeItem>> root1 = tree.get(div1);
        if (root1 == null) {
            root1 = new HashMap<>(1);
            tree.put(div1,root1);
        }

        Map<TCodeAdministrativeDivision, PollutionSourceTreeItem> root2 = root1.get(div2);
        if (root2 == null) {
            root2 = new HashMap<>(1);
            root1.put(div2,root2);
        }

        PollutionSourceTreeItem root3 = root2.get(div3);
        if (root3 == null) {
            root3 = PollutionSourceTreeItem.builder().pkId(item.getPsPkId())
                    .pollutionSourceCode(item.getPkOrgCode()).orgName(item.getOrgName()).stations(new ArrayList<>()).build();
            root3.put(station);
            root2.put(div3,root3);
        }
        else
        {
            root3.put(station);
        }



    }
}
